<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back_white.png"></image
      ></view>
      <!-- <view class="jtop_l" @tap="navigateBack">关闭</view> -->
      <view class="jtop_c">
        <view> {{ nian }}年{{ yue }}月 </view>
      </view>
      <!-- <view class="jtop_r" @tap="jshow_pop"><image src="../../static/img/ic_ellipsis_white.png"></image></view> -->
    </view>

    <view class="tophr"></view>
    <view class="content">
      <ren-calendar
        ref="ren"
        :markDays="markDays"
        :open="true"
        :disabledAfter="false"
        @onDayClick="onDayClick"
      ></ren-calendar>
      <!-- <view class="change">选中日期：{{curDate}}</view> -->
    </view>

    <!-- 无内容 -->
    <view class="no" v-if="nodata">
      <view class="no_t">
        <image src="../../static/img/index/2/ic_daily plan_grey.png"></image>
      </view>
      <view class="no_c">
        暂无日常计划
      </view>
      <view class="no_f" @tap="to_add">
        新建日常计划
      </view>
    </view>

    <view class="we" @tap="to_add" v-if="!nodata">
      <view class="we1"></view>
      <view class="we2">日常工作计划</view>
      <image
        src="../../static/img/index/new/ic_plus_circle.png"
        class="we3"
      ></image>
    </view>

    <view v-if="!nodata">
      <view
        class="wl"
        @tap="logoTime2(item.id)"
        @longpress="logoTime(item.id)"
        v-for="(item, index) in Array.prototype.reverse.call(items)"
        :key="item.id"
      >
        <view class="wl_l">
          <view class="wl_lt">
            {{ item.content }}
          </view>
          <view class="wl_lf"> 负责人：{{ item.leader }} </view>
        </view>
        <view class="wl_r">
          <image src="../../static/img/jt.png" class="wl_rr"></image>
          <view class="wl_rt">
            {{ item.beginDate | dCreateTime }} ~
            {{ item.endDate | dCreateTime }}
          </view>
        </view>
      </view>

      <!-- <view class="wl">
				<view class="wl_l">
					<view class="wl_lt">
						首层板结构施工
					</view>
					<view class="wl_lf">
						负责人：宋旋
					</view>
				</view>
				<view class="wl_r">
					<image src="../../static/img/jt.png" class="wl_rr"></image>
					<view class="wl_rt">
						08:00~13:00
					</view>
					
				</view>
			</view> -->
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop2 ? 'tc' : 'tc hide']">
      <view class="jtop_bj" @click="btTCC"></view>

      <view class="tc_fbox">
        <!-- <view class="tc_fbox_bt3" @click="btTC_bj">
					编辑
				</view> -->
        <view class="tc_fbox_bt2" @click="btTC_jdel">
          删除
        </view>
        <view class="tc_fbox_bt" @click="btTCC">
          取消
        </view>
      </view>
    </view>

    <view class="jfooter">
      <view class="jfooter_b " @tap="jf01">
        <image
          src="../../static/img/index/new/Partition_fill.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">进度计划</view>
      </view>
      <view class="jfooter_b active">
        <image
          src="../../static/img/index/new/calendar2.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">日常计划</view>
      </view>
      <view class="jfooter_b" @tap="jf03">
        <image
          src="../../static/img/index/new/shopping.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">采购计划</view>
      </view>
      <view class="jfooter_b" @tap="jf04">
        <image
          src="../../static/img/index/new/solution.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">领用计划</view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import RenCalendar from '@/components/ren-calendar/ren-calendar.vue';
export default {
  filters: {
    dCreateTime(value) {
      if (value) {
        console.log(value);
        var df = value.slice(11);
        console.log(df);
        return df;
      }
    },
  },
  components: {
    RenCalendar,
  },
  data() {
    return {
      repeat_click: true,
      curDate: '',
      markDays: [],
      collapsible: false,
      nian: '',
      yue: '',
      nodata: false,
      items: [],
      jqeditid: '',
      ashowpop2: false,
      projectId: uni.getStorageSync('dqfull_name').id,
    };
  },
  onShow() {
    // let today = this.$refs.ren.getToday().date;
    this.nian = new Date().getFullYear();
    this.yue = new Date().getMonth() + 1;

    var date = new Date();
    var Y = date.getFullYear() + '-';
    var M =
      (date.getMonth() + 1 < 10
        ? '0' + (date.getMonth() + 1)
        : date.getMonth() + 1) + '-';
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

    let today = Y + M + D;
    console.log('ddddd:', today);
    this.curDate = today;

    // this.markDays.push(today);

    this.lb(this.curDate);
  },
  methods: {
    btTC_bj() {
      var jc = this.items.filter(item => {
        return item.id == this.jqeditid;
      });

      console.log(jc);

      uni.setStorageSync('jc', jc[0]);

      uni.navigateTo({
        url: '../main/work_r_edit',
      });
    },
    logoTime2(e) {
      console.log(e);
      this.jqeditid = e;
      // this.ashowpop2 = true;

      var jc = this.items.filter(item => {
        return item.id == this.jqeditid;
      });

      console.log(jc);

      uni.setStorageSync('jc', jc[0]);

      uni.navigateTo({
        url: '../main/work_r_edit',
      });
    },

    logoTime(e) {
      console.log(e);
      this.jqeditid = e;
      this.ashowpop2 = true;
    },
    btTC_jdel() {
      var aa = this.jqeditid;
      request({
        url: `/modor/v1/project/${this.projectId}/work/plan/${aa}`,
        method: 'DELETE',

        success: res => {
          if (res.data.success == true) {
            this.lb(this.curDate);
            this.ashowpop2 = false;
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 1500,
              success: function() {
                setTimeout(function() {
                  //   uni.navigateTo({
                  // url: '../user/tream',
                  //   });
                }, 1500);
              },
            });
          } else {
            // 错误
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    btTCC(e) {
      this.ashowpop2 = !this.ashowpop2;
    },

    lb(e) {
      // var anian = new Date().getFullYear();
      // var ayue = new Date().getMonth() + 1;
      // var ayue = new Date().getDay();
      // var rq = anian+"-"+ayue+"-"+ayue
      console.log('lbbb:', e);
      var cc = e.slice(0, 7);

      // 获取列表信息
      request({
        url: `/modor/v1/project/${this.projectId}/work/plan/days`,
        method: 'GET',
        data: {
          month: cc,
        },

        success: res => {
          console.log('项目dd列表', res);
          console.log(res.data.data.length);
          if (res.data.success == true) {
            if (res.data.data.length > 0) {
              this.markDays = res.data.data;
              console.log(this.markDays);
            } else {
              this.markDays = '';
              this.dqfull_name = '';
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });

      // 获取列表信息
      request({
        url: `/modor/v1/project/${this.projectId}/work/plan/day/list`,
        method: 'GET',
        data: {
          time: e,
        },

        success: res => {
          console.log('项目列表', res);
          console.log(res.data.data.length);
          if (res.data.success == true) {
            console.log('1111:', res.data.data.length);
            if (res.data.data.length > 0) {
              this.items = res.data.data;
              console.log(this.items);
              this.nodata = false;
            } else {
              this.items = '';
              this.dqfull_name = '';
              this.nodata = true;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    navigateBack() {
      uni.switchTab({
        url: 'main',
      });
    },
    jf01() {
      uni.navigateTo({
        url: '../main/work',
      });
    },
    jf02() {
      uni.navigateTo({
        url: '../main/work_r',
      });
    },
    jf03() {
      uni.navigateTo({
        url: '../main/work_c',
      });
    },
    jf04() {
      uni.navigateTo({
        url: '../main/work_l',
      });
    },
    // 跳转
    to_add() {
      uni.navigateTo({
        url: '../main/work_r_add?curDate=' + this.curDate,
      });
    },

    onDayClick(data) {
      this.curDate = data.date;
      this.lb(data.date);
    },
  },
};
</script>

<style>
.wl {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
.wl_l {
  width: 300rpx;
  height: auto;
  display: block;
  float: left;
  margin: 21rpx 0 20rpx 30rpx;
}
.wl_lt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 0rpx 0;
}
.wl_lf {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 10rpx 0 0;
}
.wl_r {
  width: 300rpx;
  height: auto;
  display: block;
  float: right;
  margin: 42rpx 30rpx 0 0;
}
.wl_rt {
  width: auto;
  height: auto;
  display: block;
  float: right;
  margin-left: 0;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
}
.wl_rr {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 6rpx 0 0 20rpx;
}

.we {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
.we1 {
  width: 6rpx;
  height: 36rpx;
  margin: 42rpx 24rpx 0 0;
  background: #256aff;
  border-radius: 3rpx;
  display: block;
  float: left;
}
.we2 {
  width: auto;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 42rpx 0;
}
.we3 {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 36rpx 30rpx 0 0;
}

.cf {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
.cf_b {
  width: 690rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 30rpx;
}
.cf01 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 20rpx 0;
}
.cf02 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 0 0 20rpx;
}
.cf03 {
  width: 100rpx;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 34rpx;
  line-height: 32rpx;
  margin: 40rpx 40rpx 40rpx 0;
}
.cf04 {
  width: 500rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0rpx;
}
.cf04t {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 20rpx 0 10rpx;
}
.cf04f {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 0rpx 0 22rpx;
}

.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 100rpx 0 0;
}
.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}
.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}
.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}
.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}
.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}
.index {
  background: #ffffff;
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #256aff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  color: #ffffff;
  text-align: right;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #ffffff;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_c1 {
  display: inline-block;
  margin: 0 20rpx;
  color: #ffffff;
}
.jtop_c1.active {
  color: #ffffff;
}

.change {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  margin-top: 100rpx;
  height: 100rpx;
  color: #b89249;
  background-color: #21191b;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}
.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #f2f2f2;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}
.tc_fbox_bt2 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 0rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox_bt3 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-bottom: 1px solid #dddddd;
  background: #ffffff;
}

.wl_nr {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  overflow-x: auto;
}
</style>
